//
//  FSNoticeSettingSwitchCell.m
//  fanshu
//
//  Created by 许海峰 on 16/4/9.
//  Copyright © 2016年 FS. All rights reserved.
//

#import "FSNoticeSettingSwitchCell.h"
#import "FSNoticeSettingItem.h"
@interface FSNoticeSettingSwitchCell()
@property (nonatomic,weak) UISwitch *mySwitch;
@end
@implementation FSNoticeSettingSwitchCell
-(void)setItem:(FSNoticeSettingItem *)item
{
    _item = item;
    self.textLabel.text = item.title;
    if (item.icon != nil) {
        self.imageView.image = [UIImage imageNamed:item.icon];
    }
   if (_mySwitch == nil) {
        UISwitch *mySwitch = [[UISwitch alloc] init];
        mySwitch.centerY = self.height * 0.5;
        mySwitch.x = self.width - mySwitch.width - 5;
        [self addSubview:mySwitch];
        mySwitch.on = item.switchOn;
        _mySwitch = mySwitch;
        [mySwitch addTarget:self action:@selector(switchChange) forControlEvents:UIControlEventValueChanged];
   }
   
}
-(void)switchChange
{
    self.item.switchOn = self.mySwitch.on;
    [[NSNotificationCenter defaultCenter] postNotificationName:@"noticeSettingItemSwitchChange" object:self.item];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
